import { ref } from 'vue'
import { getId } from '../utils/config'


export default function newTodo(todoList) {
    const todoTitle = ref('');
    let addTodo = () => {
        console.log('todoTitle.value.trim()', todoTitle.value.trim())
        'todoTitle.value.trim()是文本框值'
        let result = todoTitle.value.trim();

        /**
         * 如果文本框无值就返回
         */
        if (!result) {
            return
        }

        /*
         *文本框值 =  title 值 
         */
        let value = {
            id: getId(),
            completed: false,
            title: result
        }
        
        todoList.value.push(value);
        todoTitle.value = '';
    }
    return {
        todoTitle,
        addTodo
    }
}